package com.anghui.demo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;

import java.util.Arrays;

public enum BusinessType {

    OTHER(0, "其他"),
    INSERT(1, "新增"),
    UPDATE(2, "修改"),
    DELETE(3, "删除"),
    SELECT(4, "查询"),
    EXPORT(5, "导出"),
    IMPORT(6, "导入");
    @EnumValue
    private int type;
    private String msg;

    BusinessType(int type, String msg) {
        this.msg = msg;
    }

    // 根据code获取枚举
    public static BusinessType fromType(int type) {
        return Arrays.stream(values())
                .filter(businessType -> businessType.type == type)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效的类型码: " + type));
    }
}
